/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 独影
 * Date: 2023-05-10
 * Time: 16:59
 */
public class LearningOperators {

    //1.算术运算符的使用，和类型提升的知识
    public static void main1(String[] args) {
        System.out.println(5/2);         //2
        System.out.println((double) 5/3);  //1.6666666666666667
        System.out.println((float) 5/3);  //1.6666666
        System.out.println(5/(float)2);   //2.5
        System.out.println((float)(5/2));  //2.0
    }

    public static void main2(String[] args) {
        System.out.println(10%3);  //1
        System.out.println(10%-3); //1
        System.out.println(-10%3); //-1
        System.out.println(-10%-3); //-1
        System.out.println(11.5%2); //1.5
    }

    //3.关系运算符,返回类型都是boolean类型
    public static void main3(String[] args) {
        System.out.println(1==5);
        System.out.println(1>5);
        System.out.println(1!=5);
        System.out.println(1<=5);
    }
    //4.逻辑运算符 &&  ||  !
    public static void main4(String[] args) {
        int a = 1;
        int b = 2;
        System.out.println(a==2 && (1/0)==0);
        System.out.println(!(a>b));
    }

    //5.位运算符  <<  >>  >>>
    public static void main5(String[] args) {
        int a = -3;
        System.out.println(a >> 2);

    }
   //6.条件运算符，也是java中唯一的三目运算符
    public static void main6(String[] args) {

        System.out.println((true == true) ? false :true);//结果为false
        System.out.println((true == true) ? (true == true) ? false : true:true);//嵌套使用

        //最好写成以下这样
        boolean  flag = (true == true) ? (true == true) ? false : true:true;
        System.out.println(flag);
    }
    //7.小练习
    public static void main7(String[] args) {
        int a = 10;
        int b =  ++a;
        int c =  a++;
        System.out.println(a);//12
        System.out.println(b);//11
        System.out.println(c);//11
        System.out.println((double)a/b);

    }
    //8.小练习
    public static void main8(String[] args) {
        int a = 10;
        int b = ++a;
        System.out.println(b);//11
        int c = a++;
        System.out.println(c);//11
    }
    //9.小练习
    public static void main(String[] args) {
      int a = 10;
        System.out.println(3<a<100);//<是关系运算符，返回值的类型是false或true，3<10结果为true，但true和100不能比较
    }
}
